package BNS.graphs;

/** Implements a simple (2-ended) undirected edge by retaining pointers to its 2 Nodes. */
public class Edge implements java.io.Serializable {
	private static final long serialVersionUID = 01L;
    public final Node from, to;
    transient double len;
	public Edge(Node f, Node t) { from=f; to=t; }
	public String toString() { return from+"-"+to; }
	
	/** tests to see if one of the ends of this Edge points to a Node with index idx.
		@param idx the index of the sought-after Node.
		*/
	public boolean contains(int idx) {
		int intA= from.getIndex();
		int intB= to.getIndex();
		return intA==idx || intB==idx;
		}
	
	/** tests to see if one of the ends of this Edge points to a Node with index idx.
		@param idx the index of the sought-after Node.
		*/
	public Node otherEnd(int idx) {
		int intA= from.getIndex();
		int intB= to.getIndex();
		return intA==idx? to : (intB==idx? from : null);
		}
	
	/** tests to see if this Edge connects Nodes with 2 given indexes.
		@param endA the index of one Node.
		@param endB the index of the other Node.
		*/
	public boolean joins(int endA, int endB) {
		int intA= from.getIndex();
		int intB= to.getIndex();
		return (endA==intA && endB==intB) || (endA==intB && endB==intA);
		}
	}

